Skip to content

feat(event-handler): add Amazon Bedrock Agents Functions Resolver #3957

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

svozza
Copy link
Contributor

@svozza svozza commented May 21, 2025

Summary

Adds a new resolver type to the event-handler package to handle lambda functions invoked by Amazon Bedrock agents.

Changes

  • Adds a new resolver class for Bedrock agents function
  • The resolver class has two public methods:
    • tool - takes an async function and a configuration object with name and description fields and registers the tool
    • resolve - accepts the lambda event and context objects from the handler and routes the request to the correct tool and returns an appropriately formatted response. Can also be used as a method or a decorator.
  • Allow user functions that return both primitive values or complex types( as long as they are JSON serializable).
  • Performs checks when registering tools for the following scenarios
    • Attempting to register more than 5 tools
    • Overwriting an existing tool
    • Receiving an event for a non-existent tool
  • Unit tests

Issue number: #3710

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@boring-cyborg boring-cyborg bot added dependencies Changes that touch dependencies, e.g. Dependabot, etc. event-handler This item relates to the Event Handler Utility tests PRs that add or change tests labels May 21, 2025
@pull-request-size pull-request-size bot added the size/XL PRs between 500-999 LOC, often PRs that grown with feedback label May 21, 2025
@dreamorosi dreamorosi changed the title wip(event-handler): add Amazon Bedrock Agents Functions Resolver feat(event-handler): add Amazon Bedrock Agents Functions Resolver May 21, 2025
}

const parameterObject: Record<string, string> = Object.fromEntries(
parameters.map((param) => [param.name, param.value])
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One of the consequences of not having vaildation using the Zod parser is that all these arguments will be strings because they are coming from the parameters object in the lambda event. This means that users will need to ensure they cast the arguments to correct type. Another option is to use the type we get in the parameters objects and cast based on that in lieu of not having Zod.

};

// biome-ignore lint/suspicious/noExplicitAny: this is a generic type that is intentionally open
type Tool<TParams = Record<string, any>> = {
Copy link
Contributor Author

@svozza svozza May 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentiioned, technically this function with only take strings because we are not using Zod to parse but in the future we will need the type to be open to accepting any arguments.

Edit: this type is too lose even if we had parsing. According to the docs the only supported types are the following:

string | number | integer | boolean | array

This comment was marked as outdated.

@github-actions github-actions bot added do-not-merge This item should not be merged need-issue This PR needs an issue before it can be reviewed/worked on further feature PRs that introduce new features or minor changes labels May 21, 2025
// biome-ignore lint/suspicious/noExplicitAny: this is a generic type that is intentionally open
type Tool<TParams = Record<string, any>> = {
// biome-ignore lint/suspicious/noConfusingVoidType: we need to support async functions that don't have an explicit return value
function: (params: TParams) => Promise<JSONValue | void>;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We use the type system here to only allow values to be returned that can be serialised to JSON.

@@ -8,3 +8,22 @@ export type {
RouteOptions,
RouterOptions,
} from './appsync-events.js';

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the difference for exporting types here and the packages/event-handler/src/types/bedrock-agent-function.ts file is here so I've exported everything.

@svozza svozza force-pushed the bedrock-agent-resolver branch from aa4e007 to 59db37b Compare May 21, 2025 15:29
public tool(
fnOrConfig: ToolFunction | Configuration,
config?: Configuration
): MethodDecorator | void {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take particular notice of this part, I've never worked with decorators before so any feedback here is particularly welcome.

@dreamorosi dreamorosi removed need-issue This PR needs an issue before it can be reviewed/worked on further do-not-merge This item should not be merged labels May 21, 2025
@svozza svozza force-pushed the bedrock-agent-resolver branch from 59db37b to 883fbfd Compare May 21, 2025 15:41
@svozza svozza force-pushed the bedrock-agent-resolver branch from 883fbfd to 6212f21 Compare May 21, 2025 15:43
@svozza svozza marked this pull request as draft May 21, 2025 15:46
@dreamorosi dreamorosi linked an issue May 21, 2025 that may be closed by this pull request
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dependencies Changes that touch dependencies, e.g. Dependabot, etc. event-handler This item relates to the Event Handler Utility feature PRs that introduce new features or minor changes size/XL PRs between 500-999 LOC, often PRs that grown with feedback tests PRs that add or change tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Amazon Bedrock Agents Functions
2 participants